package nl.jjsoft.airlock.test
{
	import flexunit.framework.TestCase;
	
	import mx.controls.Button;
	import mx.controls.Label;
	import mx.controls.TextInput;
	
	import nl.jjsoft.airlock.AirLockConstants;
	import nl.jjsoft.airlock.domain.Model;
//	import nl.jjsoft.airlock.mediator.LoginMediator;
	import nl.jjsoft.airlock.view.Setup;

	public class LoginMediatorTest extends TestCase
	{
		private static const STRONG_KEY:String = "verySafeKey1";
		private static const WEAK_KEY:String = "weak";
		
		public function LoginMediatorTest(methodName:String=null)
		{
			super(methodName);
		}
		/*
		public function testIsPasswordSafeDuringSafeSetup():void {
			var loginMediator:LoginMediator = new LoginMediator();
			
			var setup:Setup = new Setup();
			setup.safeKey1 = new TextInput();
			setup.safeKey1.text = STRONG_KEY;
			setup.safeKey2 = new TextInput();
			setup.safeKey2.text = STRONG_KEY;
			setup.secureLabel = new Label();
			setup.okButton = new Button();
			setup.okButton.enabled = false;
			
			var loginControllerMock:LoginControllerMock = new LoginControllerMock();
			loginControllerMock.expects("isKeySecure").withArg(STRONG_KEY).times(1);			
			
			loginMediator.setup = setup;
			loginMediator.loginController = loginControllerMock;
			loginMediator.safeToProceed();
			
			assertTrue(setup.okButton.enabled);
			assertEquals("Strong", setup.secureLabel.text);
		}
		
		public function testIsNotSafeToProceedWhenSafeCombinationsDoNotMatch():void {
			var loginMediator:LoginMediator = new LoginMediator();
			
			var setup:Setup = new Setup();
			setup.safeKey1 = new TextInput();
			setup.safeKey1.text = STRONG_KEY;
			setup.safeKey2 = new TextInput();
			setup.safeKey2.text = STRONG_KEY + "3";
			setup.secureLabel = new Label();
			setup.okButton = new Button();
			setup.okButton.enabled = false;
			
			var loginControllerMock:LoginControllerMock = new LoginControllerMock();
			loginControllerMock.expects("isKeySecure").withArg(STRONG_KEY).times(1);			
			
			loginMediator.setup = setup;
			loginMediator.loginController = loginControllerMock;
			loginMediator.safeToProceed();
			
			assertFalse(setup.okButton.enabled);
			assertEquals("Strong", setup.secureLabel.text);
		}
		
		public function testIsNotSafeToProceedWhenSafeCombinationsAreEmpty():void {
			var loginMediator:LoginMediator = new LoginMediator();
			
			var setup:Setup = new Setup();
			setup.safeKey1 = new TextInput();
			setup.safeKey1.text = "  ";
			setup.safeKey2 = new TextInput();
			setup.safeKey2.text = "";
			setup.secureLabel = new Label();
			setup.okButton = new Button();
			setup.okButton.enabled = false;
			
			var loginControllerMock:LoginControllerMock = new LoginControllerMock();
			loginControllerMock.expects("isKeySecure").withArg(STRONG_KEY).times(1);			
			
			loginMediator.setup = setup;
			loginMediator.loginController = loginControllerMock;
			loginMediator.safeToProceed();
			
			assertFalse(setup.okButton.enabled);
			assertEquals("Strong", setup.secureLabel.text);
		}
		
		public function testIsNotSafeToProceedWhenSafeCombinationIsWeak():void {
			var loginMediator:LoginMediator = new LoginMediator();
			
			var setup:Setup = new Setup();
			setup.safeKey1 = new TextInput();
			setup.safeKey1.text = WEAK_KEY;
			setup.safeKey2 = new TextInput();
			setup.safeKey2.text = WEAK_KEY;
			setup.secureLabel = new Label();
			setup.okButton = new Button();
			setup.okButton.enabled = false;
			
			var loginControllerMock:LoginControllerMock = new LoginControllerMock();
			loginControllerMock.keySecure = false;
			loginControllerMock.expects("isKeySecure").withArg(STRONG_KEY).times(1);			
			
			loginMediator.setup = setup;
			loginMediator.loginController = loginControllerMock;
			loginMediator.safeToProceed();
			
			assertFalse(setup.okButton.enabled);
			assertEquals("Weak", setup.secureLabel.text);
		}
		
		public function testShowSetupScreenWhenPasswordDatabaseDoesNotExist():void {
			var loginControllerMock:LoginControllerMock = new LoginControllerMock();
			loginControllerMock.doesDbExists = false;
			loginControllerMock.expects("dbExists").withArgs().times(1);
			
			var loginMediator:LoginMediator = new LoginMediator();
			loginMediator.loginController = loginControllerMock;
			loginMediator.model = new Model();
			
			loginMediator.initApplication();
			
			assertEquals(AirLockConstants.VIEW_SETUP, loginMediator.model.selectedView);			
		}
		
		public function testShowLoginScreenWhenPasswordDatabaseDoesExist():void {
			var loginControllerMock:LoginControllerMock = new LoginControllerMock();
			loginControllerMock.doesDbExists = true;
			loginControllerMock.expects("dbExists").withArgs().times(1);
			
			var loginMediator:LoginMediator = new LoginMediator();
			loginMediator.loginController = loginControllerMock;
			loginMediator.model = new Model();
			
			loginMediator.initApplication();
			
			assertEquals(AirLockConstants.VIEW_LOGIN, loginMediator.model.selectedView);			
		}
		*/
	}
}